#!/usr/bin/python

from __future__ import division
import re
import csv
import glob, os
import sys, getopt

# Example: python splitLogFile.py outputFolderPath 

file=open(sys.argv[1], "r")
outFolder = sys.argv[2]

with open(sys.argv[1]) as f:
	lines = f.readlines()

for index, item in enumerate(file, start=0):   # default is zero
	a = re.search("(End with evaluating partition (\d))", item)
	if a:	
		stop = index + 60
		strt = index - 262
 		print(strt)
		print(stop)
		print(int(a.groups()[1]))
		xfile=open(outFolder + "/Partition-" + a.groups()[1], "wb")

		counter = strt
		for indx, itm in enumerate(lines, start=strt):
			if (counter < stop):
				xfile.write(itm)
				xfile.write(str(indx) + " " ) 
				counter += 1			
		xfile.close()	

